
$(function () {
    $('#js-export').removeAttr('onclick');//去掉a标签中的onclick事件
    $("#js-export").css({'background': '#999', 'borderColor': '#999', 'color': '#fff'});
});
var exportdatas={}
var exportdatasArr=[]
/*查询数据*/
function customerMessagequery() {
    $.ajax({
        url:root.brandWebsite.listPage,
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        contentType: "application/json",
        data: JSON.stringify({
            "pageSize":"30",
            "pageNum":"1",
            "leaveSatus":$("#leaveSatus").val(),
            "websiteId":$("#websiteId").val(),
        }),
        success: function (data) {
            exportdatasArr=[]
            if(data.data.data!="" && data.data.data!=null){
                exportdatas={
                    "leaveSatus":$("#leaveSatus").val(),
                    "websiteId":$("#websiteId").val()
                }
                exportdatasArr.push(exportdatas)
                $('#js-export'). attr('onclick',"derivedatas();");
                $('#js-export').removeAttr('style');
            }else {
                $('#js-export').removeAttr('onclick');//去掉a标签中的onclick事件
                $("#js-export").css({'background': '#999', 'borderColor': '#999', 'color': '#fff'});
            }
                homePagelist(data.data, 0);
                $('.M-box3').pagination({
                    pageCount:data.data.pageCount,
                    jump: true,
                    coping: true,
                    prevContent: '上页',
                    nextContent: '下页',
                    callback: function (api) {
                        $.ajax({
                            type: "POST",
                            url:root.brandWebsite.listPage,
                            cache: false,  //禁用缓存
                            dataType: "json",
                            contentType: "application/json",
                            data: JSON.stringify({
                                "pageSize":"30",
                                "pageNum":api.getCurrent(),
                                "leaveSatus":$("#leaveSatus").val(),
                                "websiteId":$("#websiteId").val(),
                            }),
                            success: function (result) {
                                if(result.errorCode=="0"){
                                    homePagelist(result.data, 0);
                                }else {
                                    layer.msg(result.errorMessage, {icon: 5,time:1000});
                                }
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                alert(XMLHttpRequest);
                            }
                        });
                    }
                });
        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });
}
/*表格*/
var dataSource = new Array();
//table的数据源
var table;
dataSource = [];
function homePagelist(data, index){
    sessionStorage.setItem("authorizedUsers", JSON.stringify(data));
    dataSource.splice(0,dataSource.length);//清空数组
    var datashu =data.startRow+1;
    $.each(data.data, function (i, field) {

        var datashus = datashu++
        var rowData = new Array();
        rowData.push(datashus);
        rowData.push(field.personName);
        rowData.push(field.personPhone);
        rowData.push(field.leaveType);
        rowData.push(field.leaveText);
        rowData.push(field.personAdress);
        rowData.push(field.personMail);
        rowData.push(field.websiteName);
        rowData.push(field.createTime);
        rowData.push(field.leaveSatus);
        rowData.push(field.processingTime);
        rowData.push(field.leaveRemark);
        rowData.push(field.processingUser);
        rowData.push(field.id);
        dataSource.push(rowData);

    });

    initData(dataSource);
    function initData(dataSource) {
        var dttable = $('#customerMessagetable').dataTable(); // 初始化dataTable，清空上一个值
        dttable.fnClearTable(); //清空一下table
        dttable.fnDestroy(); //还原初始化了的datatable
        $("#customerMessagetable").DataTable({
            "autoWidth": false,
            "ordering": false,
            "searching": false,
            "paging": false,
            "retrieve": false,
            "destroy": false,
            "bAutoWidth": false,
            "bLengthChange": false,
            "aLengthMenu":[10,20,30],
            "oLanguage": {
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "抱歉， 没有找到",
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                "sInfoEmpty": "没有数据",
                "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "前一页",
                    "sNext": "后一页",
                    "sLast": "尾页"
                },
                "sZeroRecords": "没有检索到数据",
                "sProcessing": "<img src='./loading.gif' />"
            },
            data: dataSource,
            columnDefs: [
                {
                    "visible": true,
                    "targets": 0
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[0]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 0
                },
                {
                    "render": function (data, type, row) {
                        var val = '<span id="consignee" onmousemove="over4(\''+row[13]+'\')" onmouseout="out4(\''+row[13]+'\')" style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;width:95px;display:inline-block;">'+row[1]+'</span> <div id="mouseBoxsss'+row[13]+'" style="position:absolute;max-width: 163px; background: #fff;padding:10px;border:1px solid #ccc;display:none;">'+row[1]+'</div>';
                        return val;
                    },
                    "targets": 1
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[2]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 2
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = ""
                        if (row[3] == 1) {
                            val = '咨询'
                        }else if (row[3] == 2) {
                            val = '加盟'
                        }else if (row[3] == 3) {
                            val = '询价'
                        }else {
                            val = '投诉'
                        }
                        return val;
                    },
                    "targets": 3
                },

                {
                    "render": function (data, type, row) {
                        var val = '<span id="consignee" onmousemove="over(\''+row[13]+'\')" onmouseout="out(\''+row[13]+'\')" style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;width:95px;display:inline-block;">'+row[4]+'</span> <div id="mouseBox'+row[13]+'" style="position:absolute;max-width: 400px; background: #fff;padding:10px;border:1px solid #ccc;display:none;">'+row[4]+'</div>';
                        return val;
                    },
                    "targets": 4
                },

                {
                    "render": function (data, type, row) {
                        var val = '<span id="consignee" onmousemove="over2(\''+row[13]+'\')" onmouseout="out2(\''+row[13]+'\')" style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;width:95px;display:inline-block;">'+row[5]+'</span> <div id="mouseBoxs'+row[13]+'" style="position:absolute;max-width: 400px; background: #fff;padding:10px;border:1px solid #ccc;display:none;">'+row[5]+'</div>';
                        return val;
                    },
                    "targets": 5
                },
                {
                    "render": function (data, type, row) {
                        var val = '<span id="consignee" onmousemove="over3(\''+row[13]+'\')" onmouseout="out3(\''+row[13]+'\')" style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;width:95px;display:inline-block;">'+row[6]+'</span> <div id="mouseBoxss'+row[13]+'" style="position:absolute;max-width: 163px; background: #fff;padding:10px;border:1px solid #ccc;display:none;">'+row[6]+'</div>';
                        return val;
                    },
                    "targets": 6
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[7]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 7
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[8]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 8
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = ""
                        if (row[9] == 0) {
                            val = '待处理'
                        }else if (row[9] == 1) {
                            val = '已处理'
                        }
                        return val;
                    },
                    "targets": 9
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[10]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 10
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[11]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 11
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[12]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 12
                },

                {
                    "render": function (data, type, row, meta) {
                        var  val = '<a onclick="IntroductionCopydetails(\'详情\',\'customerDetails.html\',\''+row[13]+'\')">修改</a>';
                        return val;
                    },
                    "targets":13
                },

            ]
        });
    };
}
/*备注鼠标移出事件*/
function over(id) {
    console.log("111111111111111111")
    $("#mouseBox"+id).css({
        display: "inline"
    });
}
function out(id) {
    $("#mouseBox"+id).css({
        display: "none"
    });
}
/*联系地址鼠标移出事件*/
function over2(id) {
    $("#mouseBoxs"+id).css({
        display: "inline"
    });
}
function out2(id) {
    $("#mouseBoxs"+id).css({
        display: "none"
    });
}
/*邮箱鼠标移出事件*/
function over3(id) {
    $("#mouseBoxss"+id).css({
        display: "inline"
    });
}
function out3(id) {
    $("#mouseBoxss"+id).css({
        display: "none"
    });
}
/*姓名鼠标移出事件*/
function over4(id) {
    $("#mouseBoxsss"+id).css({
        display: "inline"
    });
}
function out4(id) {
    $("#mouseBoxsss"+id).css({
        display: "none"
    });
}
/*跳转*/
function IntroductionCopydetails(title,url,data){
    sessionStorage.setItem("customerMessageId",data);
    var index = layer.open({
        type: 2,
        title: title,
        content: url
    });
    layer.full(index);
}
//网站
querybrandWebsites()
function querybrandWebsites() {
    $.ajax({
        type: "POST",
        url: root.brandWebsite.query,
        cache: false,  //禁用缓存
        dataType: "json",
        contentType: "application/json",
        data: JSON.stringify({

        }),
        success: function (data) {
            for (var i=0;i<data.data.data.length;i++){
                $("#websiteId").append("<option value=" + data.data.data[i].id + " >" + data.data.data[i].websiteName + "</option>")

            }

        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });
}
//导出
function derivedatas() {
    console.log(exportdatasArr[0].leaveSatus)
    $('#js-export').attr('href',root.brandWebsite.exportLeaveMsgExcel+'?'+'leaveSatus='+''+exportdatasArr[0].leaveSatus+''+'&websiteId='+''+exportdatasArr[0].websiteId);
}